package com.zhang.limit;

import com.google.common.util.concurrent.RateLimiter;

/**
 * 突发型限流
 */
public class SmoothBurstyDemo {

    public static void main(String[] args) {
        System.out.println("test1 ========================= start");
        RateLimiter limiter1 = RateLimiter.create(5);
        System.out.println(limiter1.acquire());
        System.out.println(limiter1.acquire());
        System.out.println(limiter1.acquire());
        System.out.println(limiter1.acquire());
        System.out.println(limiter1.acquire());
        System.out.println(limiter1.acquire());
        System.out.println("test1 ========================= end");
        System.out.println("test2 ========================= start");
        RateLimiter limiter2 = RateLimiter.create(5);
        System.out.println(limiter2.acquire(5));
        System.out.println(limiter2.acquire(1));
        System.out.println(limiter2.acquire(1));
        System.out.println("test2 ========================= end");
        System.out.println("test3 ========================= start");
        RateLimiter limiter3 = RateLimiter.create(5);
        System.out.println(limiter3.acquire(10));
        System.out.println(limiter3.acquire(1));
        System.out.println(limiter3.acquire(1));
        System.out.println("test3 ========================= end");
    }
}
